<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" lang="zh" xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8">
    <title>设备信息</title>
    <link rel="stylesheet" href="/static/lib/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/static/css/public.css" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>
<div class="layui-form" align="center">
    <div style="font-size: 25px; height: 50px;">终端设置</div>

    <form method="post" class="layui-form">
        <div class="a" style="margin:auto 10px; width: 450px;margin-left: 50px;margin-top: 10px;">
            <div class="layui-form-item">
                <label class="layui-form-label">终端地址</label>
                <div class="layui-input-inline">
                    <input type="text" name="url" th:value="${terminals?.url}"
                           lay-reqtext="地址不能为空" lay-verify="required"
                           placeholder="请输入地址" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux">请输入地址</div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">服务器账号</label>
                <div class="layui-input-inline">
                    <input type="text" name="username" th:value="${terminals?.username}"
                           lay-reqtext="账号不能为空" lay-verify="required"
                           placeholder="请输入账号" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux">请输入账号</div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">密码</label>
                <div class="layui-input-inline">
                    <input type="password" name="password" id="pwd" th:value="${terminals?.password}"
                           lay-reqtext="密码不能为空" lay-verify="required"
                           placeholder="请输入密码" autocomplete="off" class="layui-input">
                </div>
                <div style="float: left;">
                    <input type="checkbox" lay-skin="switch" lay-filter="seePWD" lay-text="显示|隐藏">
                </div>
            </div>
        </div>

        <div class="layui-form-item" style="margin-top: 30px;">
            <button type="button" class="layui-btn layui-btn-normal" lay-submit lay-filter="testTerminals">测试连接</button>
            <button type="submit" class="layui-btn layui-btn-normal" lay-submit lay-filter="save">保存修改</button>
        </div>
    </form>

</div>
<script src="/static/lib/layui/layui.js" charset="utf-8"></script>
<script>
    layui.use(['form'], function () {
        var form = layui.form,
            layer = layui.layer,
            $ = layui.$;

        var pwd = $("#pwd");

        //密码显示隐藏
        form.on('switch(seePWD)', function (data) {
            if(data.elem.checked){
                pwd.attr('type', 'text');
            }else{
                pwd.attr('type', 'password');
            }
        });

        //监听提交
        form.on('submit(save)', function(data){
            //提交表单
            $.ajax({
                type: "put",
                url: "/terminals/update",
                dataType: "json",
                traditional: true,
                data: data.field,
                success: function (data) {
                    layer.closeAll();
                    layer.msg(data.msg);
                },
                error: function (data) {
                    layer.closeAll();
                    layer.msg("错误！请联系管理员");
                }
            });
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });

        //监听提交
        form.on('submit(testTerminals)', function(data){
            //提交表单
            $.ajax({
                type: "post",
                url: "/terminals/test",
                dataType: "json",
                traditional: true,
                data: data.field,
                success: function (data) {
                    layer.closeAll();
                    layer.msg(data.msg);
                },
                error: function (data) {
                    layer.closeAll();
                    layer.msg("错误！请联系管理员");
                }
            });
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });

    });
</script>
</body>
</html>